package main

import (
	"fmt"
	"sync"
)

type Singleton struct{}

var (
	instance *Singleton
	once     sync.Once
)

func GetInstance() *Singleton {
	once.Do(func() { // 利用锁
		fmt.Println("Initializing Singleton Instance...")
		instance = &Singleton{} // 实例仅初始化一次
	})
	return instance
}

func main() {
	s1 := GetInstance()
	s2 := GetInstance()

	fmt.Println(s1 == s2) // 输出: true，表示是同一实例
}
